package org.kjtc.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.kjtc.entity.CarForLine;
import org.kjtc.entity.CarInfo;
import org.kjtc.entity.CarTeam;
import org.kjtc.entity.DriverInfo;
import org.kjtc.entity.LineInfo;
import org.kjtc.entity.Page;
import org.kjtc.service.ActionHistoryService;
import org.kjtc.service.CarForLineService;
import org.kjtc.service.CarInfoService;
import org.kjtc.service.CarTeamService;
import org.kjtc.service.DriverService;
import org.kjtc.service.LineService;
import org.kjtc.util.Tools;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class CarController extends BaseController {

	@Resource(name = "carInfoService")
	private CarInfoService carInfoService;

	@Resource(name = "carTeamService")
	private CarTeamService carTeamService;

	@Resource(name = "carForLineService")
	private CarForLineService carForLineService;

	@Resource(name = "lineService")
	private LineService lineService;

	@Resource(name = "actionHistoryService")
	private ActionHistoryService actionHistoryService;

	// 驾驶员信息查询
	@Resource(name = "driverService")
	private DriverService driverService;

	@RequestMapping(value = "/searchDriverInfo")
	@ResponseBody
	public Map<String, Object> searchDriverInfo(DriverInfo driverInfo, String page, String rows) {

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息查询开始");
		// 分页
		Page pageQuery = getPage();
		pageQuery.setCurrentPage(Integer.parseInt(page));
		pageQuery.setCurrentResult((Integer.parseInt(page) - 1) * (Integer.parseInt(rows)));
		pageQuery.setShowCount(Integer.parseInt(rows));

		List<DriverInfo> driverInfos = null;
		try {
			driverInfos = driverService.getDriverInfoPage(driverInfo, pageQuery);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息查询异常" + e.getMessage());
			return map;
		}
		map.put("totalCnt", pageQuery.getTotalResult());
		map.put("totalPage", pageQuery.getTotalPage());
		map.put("driverInfoList", driverInfos);
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息查询结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "驾驶员信息查询");
		driverInfos = null;
		return map;
	}

	/**
	 *
	 * @param driverInfo
	 * @return 驾驶员信息添加
	 */
	@RequestMapping(value = "/saveDriverInfo")
	@ResponseBody
	public Map<String, Object> saveDriverInfo(DriverInfo driverInfo) {

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息添加开始");
		driverInfo.setCreateUser(this.getUesr().getUserID());
		driverInfo.setUpdateUser(this.getUesr().getUserID());
		int count = 0;
		try {
			count = driverService.insertDriverInfo(driverInfo);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (DuplicateKeyException ex) {
			String[] error = ex.getCause().getMessage().split("'");
			if ("PRIMARY".equals(error[3].trim())) {
				map.put("result", "CardNoExistl");
			} else if ("DriverName".equals(error[3].trim())) {
				map.put("result", "DriverNameExist");
			} else if ("TelephoneNo".equals(error[3].trim())){
				map.put("result", "TelephoneExist");
			} else if ("Email".equals(error[3].trim())) {
				map.put("result", "EmailExist");
			} else if ("WeChat".equals(error[3].trim())) {
				map.put("result", "WeChatExist");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
		    logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息添加异常" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息添加结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "驾驶员信息添加");
		driverInfo = null;
		return map;
	}

	@RequestMapping(value = "/updateDriverInfo")
	@ResponseBody
	public Map<String, Object> updateDriverInfo(DriverInfo driverInfo) {

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息修改开始");
		driverInfo.setUpdateUser(this.getUesr().getUserID());
		int count = 0;
		try {
			count = driverService.updateDriverInfo(driverInfo);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (DuplicateKeyException ex) {
			String[] error = ex.getCause().getMessage().split("'");
			if ("DriverName".equals(error[3].trim())) {
				map.put("result", "DriverNameExist");
			} else if ("TelephoneNo".equals(error[3].trim())){
				map.put("result", "TelephoneExist");
			} else if ("Email".equals(error[3].trim())) {
				map.put("result", "EmailExist");
			} else if ("WeChat".equals(error[3].trim())) {
				map.put("result", "WeChatExist");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息修改异常" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息修改结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "驾驶员信息修改");
		driverInfo = null;
		return map;
	}

	@RequestMapping(value = "/deleteDriverInfo")
	@ResponseBody
	public Map<String, Object> deleteDriverInfo(String cardNo) {

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息删除开始");
		String[] cardNoList = cardNo.split(",");
		DriverInfo driverInfo = new DriverInfo();
		driverInfo.setCardNoList(cardNoList);
		int count;
		try {
			count = driverService.deleteDriverInfo(driverInfo);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息删除异常:" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "驾驶员信息删除结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "驾驶员信息删除");
		driverInfo = null;
		return map;
	}

	@RequestMapping(value = "/searchCarTeam")
	@ResponseBody
	public Map<String, Object> searchCarTeam(CarTeam carTeam, String page, String rows){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队信息查询开始");
		// 分页
		Page pageQuery = getPage();
		pageQuery.setCurrentPage(Integer.parseInt(page));
		pageQuery.setCurrentResult((Integer.parseInt(page) - 1) * (Integer.parseInt(rows)));
		pageQuery.setShowCount(Integer.parseInt(rows));

		// 获取所有设备数据
		List<CarTeam> list = null;
		try {
			if (carTeam.getBranchCompanyID() == null || carTeam.getBranchCompanyID().isEmpty()) {
				carTeam.setBranchCompanyID(this.getBranchCompanyID());
			}
			list = carTeamService.getCarTeamPage(carTeam, pageQuery);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队信息查询异常：" + e.getMessage());
		}

		map.put("totalCnt",  pageQuery.getTotalResult());
		map.put("totalPage", pageQuery.getTotalPage());
		map.put("carTeamList", list);
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队信息查询结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车队信息查询");
		carTeam = null;
		return map;
	}

	@ResponseBody
	@RequestMapping(value = "/saveCarTeam")
	public Map<String, Object> saveCarTeam(CarTeam carTeam){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队信息添加开始");
		int count = 0;
		try {
			carTeam.setCreateUser(this.getUesr().getUserID());
			carTeam.setUpdateUser(this.getUesr().getUserID());
			count = carTeamService.insertCarTeam(carTeam);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (DuplicateKeyException ex) {
			String[] error = ex.getCause().getMessage().split("'");
			if ("PRIMARY".equals(error[3].trim())) {
				map.put("result", "TeamIDExist");
			} else if ("TeamName".equals(error[3].trim())) {
				map.put("result", "TeamNameExist");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队信息添加异常:" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队信息添加结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车队信息添加");
		carTeam = null;
		return map;
	}

	@RequestMapping(value = "/updateCarTeam")
	@ResponseBody
	public Object updateCarTeam(CarTeam carTeam){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队信息修改开始");
		int count = 0;
		try {
			carTeam.setUpdateUser(this.getUesr().getUserID());
			count = carTeamService.updateCarTeam(carTeam);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (DuplicateKeyException ex) {
			String[] error = ex.getCause().getMessage().split("'");
			if ("TeamName".equals(error[3].trim())) {
				map.put("result", "TeamNameNoNull");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队信息修改异常:" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队信息修改结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车队信息修改");
		carTeam = null;
		return map;
	}

	@RequestMapping(value = "/deleteCarTeam")
	@ResponseBody
	public Object delCarTeam(String teamIDList, String subBranchCompanyIDList){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队信息删除开始");
		String[] teamIDs = teamIDList.split(",");
		String [] subBranchCompanyIDs = subBranchCompanyIDList.split(",");
		List<CarTeam> carTeamList= new ArrayList<CarTeam>();
		for(int i = 0; i < teamIDs.length; i++){
			CarTeam carTeam = new CarTeam();
			carTeam.setTeamID(teamIDs[i]);
			carTeam.setSubBranchCompanyID(subBranchCompanyIDs[i]);
			carTeamList.add(carTeam);
			carTeam = null;
		}
		int count = 0;
		try {
			count = carTeamService.deleteCarTeam(carTeamList);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息删除异常:" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队信息删除结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车队信息删除");
		carTeamList = null;
		return map;
	}

	//查询
	@RequestMapping(value = "/searchVehicleInfo")
	@ResponseBody
	public Map<String, Object> searchVehicleInfo(CarInfo carInfo, String page, String rows) {

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基础信息查询开始");
		// 分页
		Page pageQuery = getPage();
		pageQuery.setCurrentPage(Integer.parseInt(page));
		pageQuery.setCurrentResult((Integer.parseInt(page) - 1) * (Integer.parseInt(rows)));
		pageQuery.setShowCount(Integer.parseInt(rows));

		//查询所有设备信息
		List<CarInfo> list;
		try {
			if (carInfo.getBranchCompanyID() == null || carInfo.getBranchCompanyID().isEmpty()) {
				carInfo.setBranchCompanyID(this.getBranchCompanyID());
			}
			list = carInfoService.getCarInfo(carInfo, pageQuery);
			map.put("totalCnt",  pageQuery.getTotalResult());
			map.put("totalPage", pageQuery.getTotalPage());
			map.put("carInfoList", list);

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基础信息查询异常" + e.getMessage());
			return map;
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基础信息查询结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车辆基础信息查询");
		carInfo = null;
		return map;
	}
	//添加
	@RequestMapping(value = "/saveVehicleInfo")
	@ResponseBody
	public Map<String, Object> saveVehicleInfo(CarInfo carInfo){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基础信息添加开始");
		carInfo.setDeliveryDTTM(Tools.str2Date(carInfo.getDeliveryDate()));
		carInfo.setUseDTTM(Tools.str2Date(carInfo.getUseDate()));
		carInfo.setCreateUser(this.getUesr().getUserID());
		carInfo.setUpdateUser(this.getUesr().getUserID());
		int count = 0;
		try {
			count = carInfoService.insertCarInfo(carInfo);
			if(count > 0){
				map.put("result", "Success");
			}else{
				map.put("result", "NotFound");
			}

		} catch (DuplicateKeyException ex) {
			String[] error = ex.getCause().getMessage().split("'");
			if ("CarNumber".equals(error[3].trim())) {
				map.put("result", "CarNumberNoNull");
			} else if ("CarVin".equals(error[3].trim())){
				map.put("result", "CarVinNoNull");
			} else if ("CarNumber".equals(error[3].trim())) {
				map.put("result", "CarNumberNoNull");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基础信息添加异常" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基础信息添加结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车辆基础信息添加");
		carInfo = null;
		return map;
	}
	//修改
	@RequestMapping(value = "/updateVehicleInfo")
	@ResponseBody
	public Object updateVehicleInfo(CarInfo carInfo){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基础信息修改开始");
		carInfo.setDeliveryDTTM(Tools.str2Date(carInfo.getDeliveryDate()));
		carInfo.setUseDTTM(Tools.str2Date(carInfo.getUseDate()));
		carInfo.setUpdateUser(this.getUesr().getUserID());
		int count = 0;
		try {
			count = carInfoService.updateCarInfo(carInfo);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (DuplicateKeyException ex) {
			String[] error = ex.getCause().getMessage().split("'");
			if ("CarNo".equals(error[3].trim())) {
				map.put("result", "CarNoNoNull");
			} else if ("CarVin".equals(error[3].trim())){
				map.put("result", "CarVinNoNull");
			} else if ("CarNumber".equals(error[3].trim())) {
				map.put("result", "CarNumberNoNull");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基础信息修改异常" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基础信息修改结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车辆基础信息修改");
		carInfo = null;
		return map;
	}
	//删除
	@RequestMapping(value = "/deleteVehicleInfo")
	@ResponseBody
	public Object deleteVehicleInfo(String carVin) {

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基本信息删除开始");
		String[] carInfoIDList = carVin.split(",");
		CarInfo carInfo = new CarInfo();
		carInfo.setCarInfoIDList(carInfoIDList);
		carInfo.setUpdateUser(this.getUesr().getUserID());
		int count = 0;
		try {
			count = carInfoService.deleteCarInfo(carInfo);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基本信息删除异常:" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆基本信息删除结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车辆基础信息删除");
		carInfo = null;
		return map;
	}

	@RequestMapping(value = "/searchVehicleLine")
	@ResponseBody
	public Map<String, Object> searchVehicleLine(CarForLine carForLine, String page, String rows){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息查询开始");
		// 分页
		Page pageQuery = getPage();
		pageQuery.setCurrentPage(Integer.parseInt(page));
		pageQuery.setCurrentResult((Integer.parseInt(page) - 1) * (Integer.parseInt(rows)));
		pageQuery.setShowCount(Integer.parseInt(rows));

		// 获取所有设备数据
		List<CarForLine> list = null;
		try {
			list = carForLineService.getCarForLinePage(carForLine, pageQuery);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息查询异常：" + e.getMessage());
		}

		map.put("totalCnt",  pageQuery.getTotalResult());
		map.put("totalPage", pageQuery.getTotalPage());
		map.put("carForLineList", list);
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息查询结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车辆线路信息查询");
		carForLine = null;
		return map;
	}

	@ResponseBody
	@RequestMapping(value = "/saveVehicleLine")
	public Map<String, Object> saveVehicleLine(CarForLine carForLine){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息添加开始");
		int count = 0;
		try {
			carForLine.setCreateUser(this.getUesr().getUserID());
			carForLine.setUpdateUser(this.getUesr().getUserID());
			count = carForLineService.insertCarForLine(carForLine, this.getUesr().getUserID());
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (DuplicateKeyException ex) {
			String[] error = ex.getCause().getMessage().split("'");
			if ("CarNo".equals(error[3].trim())) {
				map.put("result", "CarNoNoNull");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息添加异常:" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息添加结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车辆线路信息添加");
		carForLine = null;
		return map;
	}

	@RequestMapping(value = "/updateVehicleLine")
	@ResponseBody
	public Object updateVehicleLine(CarForLine carForLine){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息修改开始");
		int count = 0;
		try {
			carForLine.setUpdateUser(this.getUesr().getUserID());
			count = carForLineService.update(carForLine);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (DuplicateKeyException ex) {
			String[] error = ex.getCause().getMessage().split("'");
			if ("CarNo".equals(error[3].trim())) {
				map.put("result", "CarNoNoNull");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息修改异常:" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息修改结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车辆线路信息修改");
		carForLine = null;
		return map;
	}

	@RequestMapping(value = "/deleteVehicleLine")
	@ResponseBody
	public Object delVehicleLine(String IDList){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息删除开始");
		String[] ID = IDList.split(",");
		CarForLine carForLine = new CarForLine();
		carForLine.setIDList(ID);
		int count = 0;
		try {
			count = carForLineService.deleteCarForLine(carForLine);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息删除异常:" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车辆线路信息删除结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "车辆线路信息删除");
		carForLine = null;
		return map;
	}
	@RequestMapping(value = "/searchLineInfo")
	@ResponseBody
	public Map<String, Object> searchLineInfo(LineInfo lineInfo, String page, String rows){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息查询开始");
		// 分页
		Page pageQuery = getPage();
		pageQuery.setCurrentPage(Integer.parseInt(page));
		pageQuery.setCurrentResult((Integer.parseInt(page) - 1) * (Integer.parseInt(rows)));
		pageQuery.setShowCount(Integer.parseInt(rows));

		// 获取所有设备数据
		List<LineInfo> list = null;
		try {
			if (lineInfo.getBranchCompanyID() == null || lineInfo.getBranchCompanyID().isEmpty()) {
				lineInfo.setBranchCompanyID(this.getBranchCompanyID());
			}
			list = lineService.getLineInfoPage(lineInfo, pageQuery);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息查询异常：" + e.getMessage());
		}

		map.put("totalCnt",  pageQuery.getTotalResult());
		map.put("totalPage", pageQuery.getTotalPage());
		map.put("lineInfoList", list);
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息查询结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "线路信息查询");
		lineInfo = null;
		return map;
	}

	@ResponseBody
	@RequestMapping(value = "/saveLineInfo")
	public Map<String, Object> saveLineInfo(LineInfo lineInfo){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息添加开始");
		int count = 0;
		try {
			lineInfo.setCreateUser(this.getUesr().getUserID());
			lineInfo.setUpdateUser(this.getUesr().getUserID());
			count = lineService.insertLineInfo(lineInfo);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (DuplicateKeyException ex) {
			String[] error = ex.getCause().getMessage().split("'");
			if ("PRIMARY".equals(error[3].trim())) {
				map.put("result", "LineIDExist");
			} else if ("LineName".equals(error[3].trim())) {
				map.put("result", "LineNameExist");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息添加异常:" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息添加结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "线路信息添加");
		lineInfo = null;
		return map;
	}

	@RequestMapping(value = "/updateLineInfo")
	@ResponseBody
	public Object updateLineInfo(LineInfo lineInfo){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息修改开始");
		int count = 0;
		try {
			lineInfo.setUpdateUser(this.getUesr().getUserID());
			count = lineService.updateLineInfo(lineInfo);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (DuplicateKeyException ex) {
			String[] error = ex.getCause().getMessage().split("'");
			if ("LineName".equals(error[3].trim())) {
				map.put("result", "LineNameExist");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息修改异常:" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息修改结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "线路信息修改");
		lineInfo = null;
		return map;
	}

	@RequestMapping(value = "/deleteLineInfo")
	@ResponseBody
	public Object delLineInfo(String lineIDList){

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息删除开始");
		String[] lineID = lineIDList.split(",");
		LineInfo lineInfo = new LineInfo();
		lineInfo.setLineIDList(lineID);
		int count = 0;
		try {
			count = lineService.deleteLineInfo(lineInfo);
			if (count > 0) {
				map.put("result", "Success");
			} else {
				map.put("result", "NotFound");
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息删除异常:" + e.getMessage());
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "线路信息删除结束");
		actionHistoryService.saveActionHistory(this.getUesr().getUserID(), "线路信息删除");
		lineInfo = null;
		return map;
	}

}
